package com.acs.player;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.acs.player.constants.PlayerConst;
import com.acs.player.entities.Album;
import com.acs.player.entities.Music;
import com.acs.player.media.RetrieveData;
import com.acs.player.views.cover.ImageAdapter;

public class CoverActivity extends Activity {
	
	private Menu menu;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cover_view);  
		
        //CREATE COVER LIST 
		RetrieveData retrieveData = RetrieveData.getRetrieveData(this);
		List<Album> albumsList = retrieveData.getAlbumsList();
		
        GridView gridview = (GridView) findViewById(R.id.gridViewCover);
		gridview.setAdapter(new ImageAdapter(this, albumsList));
			
        //CREATE MENU
        RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.the_mother_of_all_views_navigator);       
        menu = new Menu();
        LinearLayout linearLayout = menu.createMenu(this);
        relativeLayout.addView(linearLayout);
    }
    
    @Override
    protected void onNewIntent(Intent intent) {
    	
    }
    
    public void click(View view){
    	menu.click(view);
    }
    
	public void goToCoverViewRow(int indexAlbum){
        RetrieveData retrieveData = RetrieveData.getRetrieveData(this);
        List<Music> allTracksList = retrieveData.getAllTracksList();
        
        Album album = retrieveData.getAlbumsList().get(indexAlbum);
        List<Music> albumTrackList = album.getTrackList();
        ArrayList<Integer> tracksIndex = new ArrayList<Integer>();
		for (Music music : albumTrackList) {
			int trackIndex = allTracksList.indexOf(music);
			tracksIndex.add(trackIndex);
		}
		
    	Intent intent = new Intent(CoverActivity.this, CoverRowActivity.class); 
    	intent.putIntegerArrayListExtra(PlayerConst.COVER_TRACK_INDEX_KEY, tracksIndex);	
    	startActivity(intent);
	}
}
